Add support for dynamically displaying the How You'll Learn cards#3198
Conversation
OpenAPI Changes2 changes: 0 error, 1 warning, 1 info Unexpected changes? Ensure your branch is up-to-date with |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates product pages to dynamically render the “How you’ll learn” cards based on CMS-controlled boolean fields introduced in a dependent API PR.
Changes:
- Replaces static “How you’ll learn” placeholder data with a fixed option set filtered by CMS booleans on the page object.
- Updates Course/Program product pages to pass
pageintoHowYoullLearnSection. - Extends page test factories with the new
hyl_choice_*boolean fields.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontends/main/src/app-pages/ProductPages/ProgramPage.tsx | Passes page to HowYoullLearnSection instead of default placeholder cards. |
| frontends/main/src/app-pages/ProductPages/ProgramAsCoursePage.tsx | Same as ProgramPage: switches HowYoullLearnSection to be page-driven. |
| frontends/main/src/app-pages/ProductPages/CoursePage.tsx | Same as above for course product pages. |
| frontends/main/src/app-pages/ProductPages/HowYoullLearnSection.tsx | Introduces option registry and filters cards based on hyl_choice_* fields on the page. |
| frontends/api/src/mitxonline/test-utils/factories/pages.ts | Adds defaults for the new hyl_choice_* booleans in test factories. |
| const filteredOptions = HOW_YOULL_LEARN_OPTIONS.filter( | ||
| (option) => | ||
| page.hasOwnProperty(option.name) && | ||
| (page as unknown as Record<string, boolean>)[option.name], | ||
| ) |
There was a problem hiding this comment.
Avoid calling page.hasOwnProperty(...) directly and the unknown as Record<string, boolean> cast. Prefer Object.prototype.hasOwnProperty.call(page, option.name) (or option.name in page) and update the name type to a keyof of the page types so TypeScript can enforce that option names match real API fields.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Done in commit 7dc5e6a. Changes made:
- Removed
page.hasOwnProperty(option.name)entirely — key existence is guaranteed by the typedHylChoiceKeyunion - Replaced
unknown as Record<string, boolean>withRecord<HylChoiceKey, boolean | undefined>(nounknownintermediary, plus an explicit=== truecheck to safely handle any missing/undefined fields) - Defined
HylChoiceKeyas an explicit string union of the knownhyl_choice_*field names, typed intoHowYoullLearnOption.name— a comment notes it should be replaced withExtract<keyof CoursePageItem & keyof ProgramPageItem, \hyl_choice_${string}`>` once the dependent API PR is published
Also fixed the array-index React key (addressed by the adjacent review comment): the intermediate items array was removed and the render now maps directly over filteredOptions, keying each item on option.name.
| {items.map((item, index) => ( | ||
| <HowYoullLearnItem key={index}> |
There was a problem hiding this comment.
Using the array index as a React key can cause incorrect reconciliation when cards are toggled on/off (items shift and React may reuse DOM/state for the wrong card). Use a stable key derived from the option (e.g., the hyl_choice_* name) by mapping filteredOptions directly and keying on option.name.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
|
This is ready for review but won't be mergeable until the MITx Online PR gets merged. |
bd02215 to
32deed8
Compare
|
32deed8 requires a MITx Online instance that's at commit mitodl/mitxonline@8d0b1df to work - the HYL API data was refactored significantly. |
ChristopherChudzicki
left a comment
There was a problem hiding this comment.
Tested this with your branch client via mitodl/mitxonline-api-clients#63... API data comes through well.
If you have time, i think it would be nice to
- change the factory to faker / lorem data
- add a test asserting it renders whichever ones the backend is returning
- this is complicated a bit by the icon values, I guess.
but it's a very simple component so not too worried about it.
| default: | ||
| console.warn(`Unknown how_youll_learn icon: ${src}`) | ||
| } |
There was a problem hiding this comment.
We should flag in the issue or somewhere that right now we have 3 repeated icons if you enable all of them:
Originally there was a fifth icon (we only had 2 duplicates) https://github.com/mitodl/mit-learn/blob/cdabbf911573599118eeb4766ffabd2035a659d0/frontends/main/public/images/product/icon_book_play.png but I removed it when we culled the hard-coded list down to 4.
There was a problem hiding this comment.
The "Learn From Others" and "Learn On Demand" ones are the new ones so will ping folks about that - initially i think we'll probably just not use those two. (I need to get something in place to set the defaults for existing courses, too; we discussed this in the MITx Online PR and then I forgot to put it in..)
ChristopherChudzicki
left a comment
There was a problem hiding this comment.
errr requesting a change more as a "don't forget" but
Requested change: update the api client after your mitxonline pr gets to production
looks fine otherwise, with minor comments earlier.
…ards from there; update where this gets called
Agent-Logs-Url: https://github.com/mitodl/mit-learn/sessions/ed6a7a47-f467-48eb-be2a-464691b2fe77 Co-authored-by: jkachel <945611+jkachel@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mitodl/mit-learn/sessions/ed6a7a47-f467-48eb-be2a-464691b2fe77 Co-authored-by: jkachel <945611+jkachel@users.noreply.github.com>
32deed8 to
8fcd872
Compare
….tsx Co-authored-by: Chris Chudzicki <christopher.chudzicki@gmail.com>
|
@ChristopherChudzicki the API client is updated and I think this ended up triggering a handful of other, minor changes because some types changed in the client.. if you want to give it another quick run through please do - otherwise i will plan to merge this sometime tomorrow (Friday) in the afternoon. |
What are the relevant tickets?
Closes mitodl/hq#10856
Depends on mitodl/mitxonline#3487
Description (What does it do?)
The dependent PR adds a handful of fields to the product pages that allow the cards in the How You'll Learn section to be toggled on and off. This is the other side of that; it updates the product pages to only display the cards that are checked in the CMS page.
Screenshots (if appropriate):
(Probably worth noting here that I didn't change any of the text on the 4 cards that exist. So, "Learn by Doing" seemed like it should match up with the "Practical Application" card, so that's what I set it to.)
How can this be tested?
Test with both a course page and a program page. (Ideally, also test with a program-course; those don't have a separate product page necessarily but good to check anyway.)
For the given item, go into the CMS in MITx Online and check random boxes in the How You'll Learn section and publish your changes. Then, check the product page in Learn. You should only see cards for the selected items.
Additional Context
We'll want to additionally customize this according to the kind of course or provider (or maybe some other thing). The wording and iconography may need to change for different situations - UAI versus xPRO versus MITx, etc. - which we can do in the frontend. This PR doesn't implement that, though.
This needs some text and icons for the new cards. We had these before I started mucking with it:
The new ones are "Learn From Others" and "Learn On Demand". They have the text from the issue but I reused the brains icon.